// demo 1
function* foo() {
  for (let i = 0; i < 3; i++) {
    yield i;
  }
}
let f = foo();
console.log(f.next()); // {value: 0, done: false}
console.log(f.next()); // {value: 1, done: false}
console.log(f.next()); // {value: 2, done: false}
console.log(f.next()); // {value: undefined, done: true}

// demo 2
function* count(x = 1) {
  while (true) {
    if (x % 7 === 0) {
      yield x;
    }
    x++;
  }
}
let n = count();
console.log(n.next()); // {value: 7, done: false}
console.log(n.next()); // {value: 14, done: false}
